<?php

require_once("Common/Model/CheckStrings.php");
require_once("WorkoutUpdates/Model/WorkoutUpdateTitle.php");
require_once("WorkoutUpdates/Model/WorkoutUpdateComment.php");

class WorkoutUpdateModel
{
	
	private static $errorMessage = "WorkoutUpdateModel::errorMessage";

	public function ValidateWorkoutUpdate($title, $comment, $workoutID, $updateID = null)
	{
		$validTitle = $this->ValidateTitle($title);
		$validComment = $this->ValidateComment($comment);
		$noTags = $this->areThereTags($title, $comment);
		if($validTitle && $validComment && !$noTags)
		{
			return true;
		}
		return false;
	}


	//DAFUK IS THIS?
	public function getChosenWorkoutID()
	{}

	public function getUpdateIdToEdit()
	{}
	
	public function CreateAndSaveUpdate()
	{}
	

	private function areThereTags($title, $comment)
	{	
		$bool= false;
		if(CheckStrings::hasTags($title))
		{
			$_SESSION[self::$errorMessage] = "Titeln innehåller ogiltiga tecken, tex < >";
			$bool = true;
		}
		elseif(CheckStrings::hasTags($comment))
		{
			$_SESSION[self::$errorMessage] = "Kommentaren innehåller ogiltiga tecken, tex < >";
			$bool = true;
		}
		return $bool;
	}


	private function ValidateTitle($title)
	{
		$bool = true;
		if($title < WorkoutUpdateTitle::Min_Title_Length)
		{
			$_SESSION[self::$errorMessage] = "Det har glömt att fylla i en titel";
			$bool = false;
		}
		elseif($title > WorkoutUpdateTitle::Max_Title_Length)
		{
			$_SESSION[self::$errorMessage] = "titeln får max vara 40 tecken";
			$bool = false;
		}
		return $bool;
	}


	private function ValidateComment($comment)
	{
		$bool = true;
		if($comment < WorkoutUpdateComment::Min_Comment_Length)
		{
			$_SESSION[self::$errorMessage] = "Det har glömt att fylla i en kommentar om ditt träningspass";
			$bool = false;
		}
		elseif($comment > WorkoutUpdateComment::Max_Comment_Length)
		{
			$_SESSION[self::$errorMessage] = "Kommentaren får max vara 1000tecken";
			$bool = false;
		}
		return $bool;
	}


	public function createAndSaveWorkoutUpdate($title, $comment)
	{
		$workoutUpdateToSave = WorkoutUpdate::createNewWorkoutUpdate($title, $comment);
		$this->workoutUpdateDAL->saveNewWorkoutUpdate($workoutUpdateToSave);
	}


}